package com.amit.hibernate;


import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Lab19AClent2 {

	public static void main(String[] args) {
		
		SessionFactory sessionfactory=CHibernateUtil.getfactory();
		Session session=sessionfactory.openSession();
		Transaction tx=session.beginTransaction();
		Customer cust=(Customer) session.load(Customer.class, 1);
		System.out.println(cust.getCid()+" "+cust.getCname()+" "+cust.getEmail()+" "+cust.getPhone());
		Set<Order> orders=cust.getOrders();
		System.out.println(orders.getClass().getName());
		
		for(Order od:orders)
		{
			System.out.println(od.getOrderId()+" "+od.getTotalQty()+" "+od.getTotalCost()+" "+od.getTotalCost());
		}
		
		Order ord=(Order) session.load(Order.class, 2);
		System.out.println(ord.getOrderId()+" "+ord.getTotalQty()+" "+ord.getTotalCost());
		
		Customer cus=ord.getCustomer();
		
		System.out.println(cus.getCid()+" "+cus.getCname()+" "+cus.getEmail());
		
		
		tx.commit();
		session.close();
		
	
	}

}
